﻿using System;
using System.Linq;
using System.Web;
using System.Data;
using System.Text.RegularExpressions;//引入正则表达式命名空间
using System.Text;

namespace msBsc.WebUi
{
    public partial class wfGoodsSearch : msBsc.Cls.BPage
    {
        protected override void OnInit(EventArgs e)
        {
            //metacontent = "";

            base.OnInit(e);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //SetContrlValue("spnTeest", GetFormParamByStr("para"));
            ////Label1.Text = Page.RouteData.Values["para"] as string;   // “para”就是所设置的路由地址的参数
            if (!IsPostBack)
            {
                ShowData();
            } 
            //msBsc.AppLogic.Cfg.JSCompress oJSCompress = new AppLogic.Cfg.JSCompress();
            //oJSCompress.doCompress(msBsc.AppLogic.Cfg.SystemFileDir.FileDir.GetMapPathByVpath("jqPlugin/js/jQueryCmd.js"), msBsc.AppLogic.Cfg.SystemFileDir.FileDir.GetMapPathByVpath("jqPlugin/js/jQueryCmd2.js"));
        }

        private void ShowData()
        {
            oGoodsSearch = new AppLogic.DataAlc.GoodsSearch(HttpUtility.UrlDecode(this.Request.QueryString.ToString()),"0");
            this.ExecJScript("$('#txtQuery').val('" + msBsc.AppLogic.Cfg.HttpTools.stringToJson(oGoodsSearch.GetQueryStr("","")) + "');");
            LoadTopForm();
            LoadGoodsList("", "", "");
        }

        private msBsc.AppLogic.DataAlc.GoodsSearch oGoodsSearch;
        public void LoadTopForm()
        {
            System.Text.StringBuilder sbJson = new StringBuilder();
            string strf = oGoodsSearch.dicQuery.ContainsKey("f") ? oGoodsSearch.dicQuery["f"] : "";
            sbJson.Append("{");
            sbJson.Append("\"f\":\"" + msBsc.AppLogic.Cfg.HttpTools.stringToJson(strf) + "\"");
            sbJson.Append(",\"query\":\"" + msBsc.AppLogic.Cfg.HttpTools.stringToJson(oGoodsSearch.GetQueryStr("", "")) + "\"");
            sbJson.Append(",\"nav_rows\":" + oGoodsSearch.GetSelectedLinkJson());
            sbJson.Append(",\"form_rows\":" + oGoodsSearch.GetFilterDataJson());
            sbJson.Append("}");

//            this.ExecJScript(@"debugger;
//");
            this.ExecJScript(@" var data= " + sbJson.ToString() + @" ; 
doBoundTopForm( data,'');");
        }
        public void LoadGoodsList(string CurrPageNum, string strPageRowsCount, string strSort)
        {
            this.ExecJScript(@" var data= " + oGoodsSearch.GetGoodsList(CurrPageNum, strPageRowsCount, strSort) + @" ; 
                doBoundGoodsList( data,'');");
        }

        public override void DoAction()
        {
            if (this.strAction == "doToPageNum")
            {
                string strq = this.GetParamHtValue("F_QUERY");
                if (this.GetParamHtValue("start_price") != string.Empty)
                {
                    strq += "&p1=" + this.GetParamHtValue("start_price");
                }
                else
                {
                    strq.Replace("p1=", "pd=");
                }
                if (this.GetParamHtValue("end_price") != string.Empty)
                {
                    strq += "&p2=" + this.GetParamHtValue("end_price");
                }
                else
                {
                    strq.Replace("p2=", "pd=");
                }
                oGoodsSearch = new AppLogic.DataAlc.GoodsSearch(this.GetParamHtValue("F_QUERY"),"0");
                LoadGoodsList(
                     this.GetParamHtValue("NEW_PAGE_NUM")
                    , this.GetParamHtValue("PAGE_ROW_COUNT")
                    , this.GetParamHtValue("PAGE_ROW_SORT"));
            } 
        }
         
    }
}